﻿@using Seal.Model
@using Seal.Helpers
@using SealWebServer.Controllers
@{
    MainModel model = Model as MainModel;
    Repository repository = model.Repository;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>@(string.IsNullOrEmpty(model.Title) ? repository.Configuration.WebProductName : model.Title)</title>
    <meta charset="utf-8" />

    <link href="~/Images/faviconWebServer.ico" rel="shortcut icon" type="image/x-icon" />

    <link rel="stylesheet" href="~/Content/datatables.min.css" />
    <link rel="stylesheet" href="~/Content/font-awesome.min.css" />
    <link rel='stylesheet' href='~/Content/jstree-style.min.css' />
    <link rel="stylesheet" href="~/Content/bootstrap-select.min.css" />
    <link rel='stylesheet' href='~/Content/bootstrap-datetimepicker.min.css' />
    <link rel="stylesheet" href="~/Content/sealweb.css" />
    <link rel="stylesheet" href="~/Content/nv.d3.min.css" />
    @foreach (var fileName in Helper.GetStringList(repository.Configuration.CssFiles))
    {
        <link rel="stylesheet" href="~/Content/@fileName" />
    }
    <link rel="stylesheet" href="~/Content/seal.css" />

</head>
<body>
    <!--disable autofill for Chrome-->
    <input type="text" style="display:none">
    <input type="password" style="display:none">

    @await Html.PartialAsync("~/Views/Home/Menu.cshtml")

    <!--Reports view -->
    <div id="main-container" class="container-fluid folderview" style="padding-top:62px; display:none;">
        <div class="row">
            <div id="folder-view" class="col-sm-4" style="padding-right:0px">
                <div class="jstree jstree-default" id="folder-tree" role="tree" style="overflow:auto;"></div>
            </div>

            <div id="file-view" class="col-sm-8" style="padding-right:0px">
                <!-- Report Menus -->
                <div id="file-menu" class="lighticon-menu hidden-xs" style="margin-bottom:10px">
                    <div id="report-edit-lightbutton" class="lightbutton report-edit"><span class="lightbutton-icon fa fa-file-o"></span><br /><span class="lightbutton-text">@repository.TranslateWeb("New")</span></div>
                    <div id="report-cut-lightbutton" class="lightbutton"><span class="lightbutton-icon fa fa-cut"></span><br /><span class="lightbutton-text">@repository.TranslateWeb("Cut")</span></div>
                    <div id="report-copy-lightbutton" class="lightbutton"><span class="lightbutton-icon fa fa-copy"></span><br /><span class="lightbutton-text">@repository.TranslateWeb("Copy")</span></div>
                    <div id="report-paste-lightbutton" class="lightbutton"><span class="lightbutton-icon fa fa-paste"></span><br /><span class="lightbutton-text">@repository.TranslateWeb("Paste")</span></div>
                    <div id="report-delete-lightbutton" class="lightbutton"><span class="lightbutton-icon fa fa-remove"></span><br /><span class="lightbutton-text">@repository.TranslateWeb("Delete")</span></div>
                    <div id="report-rename-lightbutton" class="lightbutton"><span class="lightbutton-icon fa fa-file-text"></span><br /><span class="lightbutton-text">@repository.TranslateWeb("Rename")</span></div>
                </div>
                <div id="file-table-view" style="overflow:auto;">
                    <table id="file-table" class="table table-striped table-hover">
                        <thead id="file-table-head"></thead>
                        <tbody id="file-table-body"></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <!--Dashboard view-->
    <div id="main-dashboard" class="container-fluid dashboardview" style="padding-top:62px; display:none;">
        <ul id="menu-dashboard" class="nav nav-pills"></ul>
        <div id="content-dashboard" class="tab-content">
        </div>
    </div>


    <!--Wait Dialog-->
    <div class="modal fade in" id="wait-dialog" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body" style="text-align:center">
                    <i class="fa fa-spinner fa-spin fa-2x fa-fw"></i>
                    <h3 style="display:inline">@repository.TranslateWeb("Please wait")...</h3>
                </div>
            </div>
        </div>
    </div>

    <!-- Views and Output -->
    <div id="output-panel" class="panel panel-default" style="display:none; border-color:black;">
        <div class="panel-heading" style="height:20px;padding: 0px 10px;"><button type='button' id="output-panel-close" class='close'>&times;</button></div>
        <div id="output-panel-content">
            <table class="table table-striped">
                <thead>
                    <tr><th>@repository.TranslateWeb("Name")</th><th>@repository.TranslateWeb("Type")</th></tr>
                </thead>
                <tbody id="output-table-body"></tbody>
            </table>
        </div>
    </div>

    <!-- File Name Dialog -->
    <div id="report-name-dialog" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false" style="z-index:25000;">
        <div class="modal-dialog">
            <div class="modal-content" style="top:60px">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="@repository.TranslateWeb("Close")"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">@repository.TranslateWeb("Enter your new file name")</h4>
                </div>
                <div class="modal-body">
                    <input id="report-name" type="text" class="form-control" placeholder="@repository.TranslateReport("New report")" />
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">@repository.TranslateWeb("Cancel")</button>
                    <button id="report-name-save" type="button" class="btn btn-primary">@repository.TranslateWeb("Save")</button>
                </div>
            </div>
        </div>
    </div>

    <!-- Message Dialog -->
    <div id="message-dialog" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false" style="z-index:25000;">
        <div class="modal-dialog">
            <div class="modal-content" style="top: 60px;">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="@repository.TranslateWeb("Close")"><span aria-hidden="true">&times;</span></button>
                    <h4 id="message-title" class="modal-title"></h4>
                </div>
                <div class="modal-body">
                    <span id="message-text"></span>
                </div>
                <div class="modal-footer">
                    <button id="message-cancel-button" type="button" class="btn btn-default" data-dismiss="modal">@repository.TranslateWeb("Cancel")</button>
                    <button id="message-ok-button" type="button" class="btn btn-primary">@repository.TranslateWeb("OK")</button>
                </div>
            </div>
        </div>
    </div>

    <!-- Login Modal -->
    <div id="login-modal" class="modal fade" role="dialog" data-backdrop="static" data-keyboard="false" style="top:50px;z-index:25000;">
        <div class="modal-dialog">
            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header btn-success" style="color:white;text-align:center;font-size:30px;border-top-left-radius:6px;border-top-right-radius:6px;">
                    <h4 style="color:white;"><span class="glyphicon glyphicon-lock"></span> @repository.Configuration.WebProductName @repository.TranslateWeb("Login")</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="username"><span class="glyphicon glyphicon-user"></span> @repository.TranslateWeb("User name")</label>
                        <input type="text" class="form-control" id="username" name="username" placeholder="@repository.TranslateWeb("Enter user name")" />
                    </div>
                    <div class="form-group">
                        <label for="password"><span class="glyphicon glyphicon-eye-open"></span> @repository.TranslateWeb("Password")</label>
                        <input type="password" class="form-control" id="password" placeholder="@repository.TranslateWeb("Enter password")" />
                    </div>
                    <button id="login-modal-submit" class="btn btn-default btn-success btn-block"><span class="glyphicon glyphicon-off"></span> @repository.TranslateWeb("Login")</button>
                </div>
                <div class="modal-footer" style="text-align:left">
                    <span id="login-modal-error" class="label label-danger" style="font-size: 12px;"></span>
                </div>
            </div>
        </div>
    </div>

    <!-- Profile Modal -->
    <div id="profile-dialog" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false">
        <div class="modal-dialog">
            <div class="modal-content" style="top:60px">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="@repository.TranslateWeb("Close")"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">@repository.TranslateWeb("Profile information")</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="profile-user"><span class="fa fa-user"></span> @repository.TranslateWeb("User name")</label>
                        <input class="form-control" id="profile-user" disabled="disabled" />
                    </div>
                    <div class="form-group">
                        <label for="profile-groups"><span class="fa fa-users"></span> @repository.TranslateWeb("User groups")</label>
                        <input class="form-control" id="profile-groups" disabled="disabled" />
                    </div>
                    <div class="form-group">
                        <label for="culture-select"><span class="fa fa-language"></span> @repository.TranslateWeb("Culture")</label>
                        <div>
                            <select id="culture-select" data-width="100%"></select>
                        </div>
                    </div>
                    <div class="form-group" id="view-select-group">
                        <label for="view-select"><span class="fa fa-bars"></span> @repository.TranslateWeb("Default view")</label>
                        <div>
                            <select id="view-select" data-width="100%"></select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">@repository.TranslateWeb("Cancel")</button>
                    <button id="profile-save" type="button" class="btn btn-primary">@repository.TranslateWeb("Save")</button>
                </div>
            </div>
        </div>
    </div>

    <!-- Folder Modal -->
    <div id="folder-dialog" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false">
        <div class="modal-dialog">
            <div class="modal-content" style="top:60px">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">@repository.TranslateWeb("Manage Folders")</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <input class="form-control" style="display:inline;width:50%;" id="create-folder-name" placeholder="@repository.TranslateWeb("New folder name")" />
                        <button id="folder-create" type="button" class="btn btn-primary">@repository.TranslateWeb("Create new folder")</button>
                    </div>
                    <div class="form-group">
                        <input class="form-control" style="display:inline;width:50%;" id="rename-folder-name" placeholder="@repository.TranslateWeb("New folder path")" />
                        <button id="folder-rename" type="button" class="btn btn-primary">@repository.TranslateWeb("Rename or move folder")</button>
                    </div>
                    <div class="form-group">
                        <button id="folder-delete" type="button" class="btn btn-primary">@repository.TranslateWeb("Delete folder")</button>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">@repository.TranslateWeb("Close")</button>
                </div>
            </div>
        </div>
    </div>

    <!-- Dashboard Modal -->
    <div id="dashboard-dialog" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false">
        <div class="modal-dialog">
            <div class="modal-content" style="top:60px">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">@repository.TranslateWeb("Manage Dashboards")</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <h5 id="dashboard-view-label" style="font-style:italic;font-weight:bold;"></h5>
                        <button id="dashboard-swapview" type="button" class="btn btn-primary"></button>
                    </div>
                    <div class="form-group">
                        <h5>@repository.TranslateWeb("Update dashboards displayed in your personal view")</h5>
                        <select id="dashboard-user" data-width="60%" multiple="multiple"></select>
                        <button id="dashboard-add" type="button" class="btn btn-primary">@repository.TranslateWeb("Add dashboards")</button>
                    </div>
                    <div class="form-group">
                        <select id="dashboard-toremove" data-width="60%" multiple="multiple"></select>
                        <button id="dashboard-remove" type="button" class="btn btn-primary">@repository.TranslateWeb("Remove dashboards")</button>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">@repository.TranslateWeb("Close")</button>
                </div>
            </div>
        </div>
    </div>

    <!-- Export Modal -->
    <div id="export-dialog" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false">
        <div class="modal-dialog">
            <div class="modal-content" style="top:60px">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">@repository.TranslateWeb("Export Dashboards")</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="form-horizontal col-sm-10" role="form">
                            <div class="form-group">
                                <label class="control-label col-sm-6" for="export-dashboards">@repository.TranslateWeb("Dashboards to export")</label>
                                <div class="col-sm-6">
                                    <select id="export-dashboards" multiple="multiple"></select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-6" for="export-format">@repository.TranslateWeb("Format")</label>
                                <div class="col-sm-6">
                                    <select id="export-format"></select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-6" for="export-title">@repository.TranslateWeb("Title")</label>
                                <div class="col-sm-6">
                                    <input id="export-title" class="form-control" value="@repository.TranslateWeb("Dashboard")">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-6" for="export-delay">@repository.TranslateWeb("PDF Conversion delay")</label>
                                <div class="col-sm-6">
                                    <input id="export-delay" class="form-control numeric_input" value="5">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                    <div class="modal-footer">
                        <button id="dashboard-export" type="button" class="btn btn-primary" data-dismiss="modal">@repository.TranslateWeb("Export")</button>
                    </div>
                </div>
        </div>
    </div>

    @if (model.HasEditor() && !model.Exporting)
    {
        @await Html.PartialAsync("~/Views/Home/MainEditor.cshtml");
    }

    <div id="footer-div" style="position:fixed; bottom:10px; text-align:center; width:100%">
        <div>
            <p>Copyright &copy; @DateTime.Now.Year Seal Report. All Rights Reserved (version <span id="footer-version">@Repository.ProductVersion</span>)</p>
        </div>
    </div>

    <script src="~/Scripts/datatables.min.js"></script>
    <script src="~/Scripts/jstree.min.js"></script>
    <script src="~/Scripts/bootstrap-select.min.js"></script>
    <script type="text/javascript" src="~/Scripts/moment.min.js"></script>
    @if (repository.CultureInfo.TwoLetterISOLanguageName != "en")
    {
        <script src="~/Scripts/@("i18n/moment." + repository.CultureInfo.TwoLetterISOLanguageName + ".js")"></script>
        <script src="~/Scripts/@("i18n/selectpicker." + repository.CultureInfo.TwoLetterISOLanguageName + ".min.js")"></script>
    }
    <script src="~/Scripts/bootstrap-datetimepicker.min.js"></script>
    <script src="~/Scripts/datetime-moment.js"></script>

    <!-- muuri -->
    <script src='~/Scripts/web-animations.min.js'></script>
    <script src='~/Scripts/hammer.min.js'></script>
    <script src='~/Scripts/muuri.min.js'></script>

    <!-- libraries for widgets execution -->
    <script src="~/Scripts/helpers.js"></script>
    <script src="~/Scripts/d3.min.js"></script>
    @if (repository.CultureInfo.TwoLetterISOLanguageName != "en")
    {
        <script src="~/Scripts/d3-time.v1.min.js"></script>
        <script src="~/Scripts/d3-time-format.v2.min.js"></script>
        <script src="~/Scripts/@("d3/" + repository.CultureInfo.TwoLetterISOLanguageName + ".js")"></script>
    }
    <script src="~/Scripts/nv.d3.min.js"></script>
    <script src="~/Scripts/chartNVD3.js"></script>
    <script src="~/Scripts/Chart.min.js"></script>
    <script src="~/Scripts/plotly-latest.min.js"></script>
    @if (repository.CultureInfo.TwoLetterISOLanguageName != "en")
    {
        <script src="~/Scripts/plotly/@("plotly-locale-" + repository.CultureInfo.TwoLetterISOLanguageName + ".js")"></script>
    }

    @foreach (var fileName in Helper.GetStringList(repository.Configuration.ScriptFiles))
    {
        <script type='text/javascript' src='~/Scripts/@fileName'></script>
    }

    <script type="text/javascript">
        //server
        var WebApplicationName = '@HomeController.GetWebUrl(Context.Request, Context.Response)';
        var urlPrefix = WebApplicationName;
        var inReport = false;

        //formats
        var dateSeparator = '@Html.Raw(repository.CultureInfo.DateTimeFormat.DateSeparator)';
        var decimalSeparator = '@Html.Raw(repository.CultureInfo.NumberFormat.NumberDecimalSeparator)';
        var thousandSeparator = '@Html.Raw(Helper.ToJS(repository.CultureInfo.NumberFormat.NumberGroupSeparator))';
        var currencySymbol = '@Html.Raw(Helper.ToJS(repository.CultureInfo.NumberFormat.CurrencySymbol))';
        var dirSeparator = '@(System.IO.Path.DirectorySeparatorChar == '\\' ? "\\\\" : System.IO.Path.DirectorySeparatorChar.ToString())';
        //for datepicker
        var languageName = '@repository.CultureInfo.TwoLetterISOLanguageName';
        var shortDateFormat = '@repository.MomentJSShortDateFormat';
        var shortDateTimeFormat = '@repository.MomentJSShortDateTimeFormat';
        var isUSdate = shortDateFormat.match(/^m/i);
        var printLayout = false;
        var exportFormat = '@(model.Format)';
        var exportIds = '@(model.DashboardIds)'.split(',');

        var folderRightSchedule = @((int) FolderRight.Schedule);
        var folderRightEdit = @((int) FolderRight.Edit);

        //translations
        var tra = [];
        @foreach(var translation in repository.JSTranslations)
        {
        <text>tra["@Helper.ToJS(translation.Key)"] = "@Helper.ToJS(translation.Value)";</text>
        }
        var opers = [];
        @if (model.HasEditor())
        {
        foreach (var oper in Enum.GetValues(typeof(Operator)))
        {
        <text>opers[@((int)oper)] = "@Helper.ToJS(repository.TranslateWebJS(Helper.GetEnumDescription(typeof(Operator), oper)))";</text>
        }
        }

        //datatables defaults
        $.fn.dataTable.moment(shortDateFormat);
        $.fn.dataTable.moment(shortDateTimeFormat);
        $.extend( true, $.fn.dataTable.defaults, {
                responsive: {
                    details: {
                        renderer: function (api, rowIdx, columns) {
                            return dtRenderer(api, rowIdx, columns);
                        }
                    }
                },
                columnDefs: [
                    { orderable: false, targets: ["firstcell"]},
                        {
                            targets: "_all",
                            createdCell: function (td, cellData, rowData, row, col) {
                                dtCreatedCell(td, cellData, rowData, row, col);
                            }
                        }
            ],
            language: {
                decimal: decimalSeparator,
                thousands: thousandSeparator,
                processing: "@repository.TranslateReport("Processing...")",
                lengthMenu: "@repository.TranslateReport("Show _MENU_ rows")",
                zeroRecords: "@repository.TranslateReport("No rows")",
                emptyTable: "@repository.TranslateReport("No records")",
                info: "@repository.TranslateReport("Showing _START_ to _END_ of _TOTAL_")",
                infoEmpty: "@repository.TranslateReport("Showing 0 to 0 of 0")",
                infoFiltered: "@repository.TranslateReport("(filtered from _MAX_)")",
                infoPostFix: "",
                search: "@repository.TranslateReport("Filter:")",
                paginate: {
                    first: "|&lt;",
                    previous: "&lt;&lt;",
                    next: ">>",
                    last: ">|"
                }
            },
            pagingType: "full_numbers",
            autoWidth: false,
            stateSave: false,
        });

        var dtTooltips = {
            today: '@repository.TranslateReportToJS("Go to today"))',
            clear: '@repository.TranslateReportToJS("Clear selection")',
            close: '@repository.TranslateReportToJS("Close")',
            selectMonth: '@repository.TranslateReportToJS("Select Month")',
            prevMonth: '@repository.TranslateReportToJS("Previous Month")',
            nextMonth: '@repository.TranslateReportToJS("Next Month")',
            selectYear: '@repository.TranslateReportToJS("Select Year")',
            prevYear: '@repository.TranslateReportToJS("Previous Year")',
            nextYear: '@repository.TranslateReportToJS("Next Year")',
            selectDecade: '@repository.TranslateReportToJS("Select Decade")',
            prevDecade: '@repository.TranslateReportToJS("Previous Decade")',
            nextDecade: '@repository.TranslateReportToJS("Next Decade")',
            prevCentury: '@repository.TranslateReportToJS("Previous Century")',
            nextCentury: '@repository.TranslateReportToJS("Next Century")',
            pickHour: '@repository.TranslateReportToJS("Pick Hour")',
            incrementHour: '@repository.TranslateReportToJS("Increment")',
            decrementHour: '@repository.TranslateReportToJS("Decrement")',
            pickMinute: '@repository.TranslateReportToJS("Pick Minute")',
            incrementMinute: '@repository.TranslateReportToJS("Increment")',
            decrementMinute: '@repository.TranslateReportToJS("Decrement")',
            pickSecond: '@repository.TranslateReportToJS("Pick Second")',
            incrementSecond: '@repository.TranslateReportToJS("Increment")',
            decrementSecond: '@repository.TranslateReportToJS("Decrement")',
            togglePeriod: '@repository.TranslateReportToJS("Toggle Period")',
            selectTime: '@repository.TranslateReportToJS("Select Time")'
        };


        //keyword
        var displayNameKeyword = '@Repository.SealReportDisplayNameKeyword2';

        var hasEditor = @Helper.ToJS(model.HasEditor() && !model.Exporting);
        //specific for widget execution
        function nvd3TranslateText(text)
        {
            @foreach (var translation in repository.NVD3Translations)
            {
            <text>if (text == '@Html.Raw(Helper.ToJS(translation.Key))') return '@Html.Raw(Helper.ToJS(translation.Value))';</text>
            }
            return text;
        }
    </script>

    @if (!model.HasMinifiedScripts())
    {
        <script src="~/Scripts/swi-utils.js"></script>
        <script src="~/Scripts/swi-gateway.js"></script>
        <script src="~/Scripts/swi-dashboard.js"></script>
        <script src="~/Scripts/swi-main.js"></script>

        if (model.HasEditor() && !model.Exporting)
        {
            <script src="~/Scripts/swi-button-group.js"></script>
            <script src="~/Scripts/swi-editor.js"></script>
            <script src="~/Scripts/swi-properties.js"></script>
            <script src="~/Scripts/swi-dashboard-editor.js"></script>
        }
    }
    else
    {
        <script src="~/Scripts/swi.js"></script>
    }

</body>
</html>
